Skip to content

fix: remediate critical security vulnerabilities (CSRF, negative amounts, race conditions)#176

Open
devin-ai-integration[bot] wants to merge 4 commits intoDevOpsfrom
devin/1777413094-security-remediation
Open

fix: remediate critical security vulnerabilities (CSRF, negative amounts, race conditions)#176
devin-ai-integration[bot] wants to merge 4 commits intoDevOpsfrom
devin/1777413094-security-remediation

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 28, 2026

Summary

Remediates 5 confirmed security vulnerabilities identified by the Hunter Agent Pipeline security audit:

Critical — Dynamically Confirmed Exploitable:

  1. AUTH-AUTHZ-001: CSRF Protection Globally Disabled — Re-enabled Spring Security CSRF protection (was csrf.disable()). Updated all Thymeleaf forms to use th:action for automatic CSRF token injection.
  2. FINOPS-AUTHZ-002: Negative Amount Exploit — Added server-side validation that all financial amounts (deposit, withdraw, transfer) must be strictly positive. Previously, POST /withdraw amount=-5000 created $5,000 from nothing.

Critical — Code-Confirmed:
3. FINOPS-RACE-001: Concurrent Withdraw Double-Spend — Added @Transactional + PESSIMISTIC_WRITE locking on all financial operations.
4. FINOPS-RACE-002: Concurrent Transfer Double-Spend — Same fix pattern applied to transfer operations, with deterministic lock ordering (alphabetical by username) to prevent ABBA deadlocks.

Additional Hardening:
5. Input validation on registration (username format, password length, enumeration mitigation)
6. Error handling added to deposit controller endpoint
7. HTML min="1" constraint on amount input fields
8. H2 in-memory database profile added for local security testing
9. Register template updated to show dynamic error messages instead of hardcoded text

Files Changed (9)

  • SecurityConfig.java — CSRF re-enabled
  • AccountService.java — Amount validation, @transactional, pessimistic locking with deterministic ordering, input validation
  • BankController.java — Deposit error handling
  • AccountRepository.java — Pessimistic locking query
  • dashboard.html, login.html, register.html — th:action for CSRF tokens, min amount, dynamic errors
  • application-h2.properties — H2 test profile
  • pom.xml — H2 dependency for testing

Review & Testing Checklist for Human

  • Verify CSRF protection works: attempt any POST (deposit/withdraw/transfer) without a CSRF token — should get HTTP 403
  • Verify negative amounts rejected: try POST /deposit amount=-100 and POST /withdraw amount=-500 — both should show error, balance unchanged
  • Verify legitimate transactions still work: deposit, withdraw, and transfer with positive amounts and valid CSRF tokens
  • Verify registration validation: try registering with password < 8 chars — should see "Password must be at least 8 characters" (not "User already present")
  • Review pessimistic locking in AccountService.java — all financial methods use findByUsernameForUpdate() with @Lock(PESSIMISTIC_WRITE), transfer uses deterministic lock ordering

Recommended test plan: Start the app with H2 profile (./mvnw spring-boot:run -Dspring-boot.run.profiles=h2), register two accounts, deposit funds, then verify all the above checklist items.

Notes

  • Account lockout (AUTH-AUTHZ-003) is deferred — requires infrastructure-level changes (AuthenticationFailureHandler + attempt counter). Tracked as a follow-up recommendation.
  • The H2 profile (application-h2.properties) is for local testing only and does not affect the production MySQL configuration.
  • All 6 revalidation tests passed after remediation.
  • Addressed Devin Review findings: deterministic lock ordering in transferAmount() and dynamic error messages in register.html.

Link to Devin session: https://app.devin.ai/sessions/24fd567d7b324669bcf46b04821b01a0
Requested by: @angelalincog


Open in Devin Review

…nts, race conditions)

- Enable CSRF protection in SecurityConfig (was globally disabled)
- Add positive amount validation on deposit, withdraw, transfer operations
- Add @transactional and pessimistic locking to prevent race conditions
- Add username/password input validation on registration
- Update Thymeleaf templates to use th:action for CSRF token injection
- Add error handling for deposit controller endpoint
- Add H2 test profile for local security testing
- Add min=1 constraint on HTML amount input fields

Co-Authored-By: Angela  Lin <angela.lin@cognition.ai>
@staging-devin-ai-integration
Copy link
Copy Markdown

Devin Review

Status Commit
⚪ Not started

Open in Devin Review (Staging)

💡 Connect your GitHub account to enable automatic code reviews.

@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Co-Authored-By: Angela  Lin <angela.lin@cognition.ai>
devin-ai-integration[bot]

This comment was marked as resolved.

…dynamic error messages

- Fix ABBA deadlock risk in transferAmount by acquiring locks in
  alphabetical username order
- Fix register.html to display dynamic error messages instead of
  hardcoded 'User already present'

Co-Authored-By: Angela  Lin <angela.lin@cognition.ai>
devin-ai-integration[bot]

This comment was marked as resolved.

Co-Authored-By: Angela  Lin <angela.lin@cognition.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant